<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
	<ui:composition template="/design/template.xhtml">
    <ui:define name="body">

      <h:form id="frmListaConcursos" >
      <p:panel id="pnlListaConcursos" header="Concursos">

      <p:spacer height="10" />
      <p:messages id="messages" autoUpdate="true" />
      
      <p:dataTable id="tblConcurso" value="#{adminConcursoAction.concursos}" var="concurso" style="width:100%;" columnsWidth="10%,30%,30%,20%,10%">

        <p:column style="text-align:center;">
          <f:facet name="header">
            <h:outputText value="Código" />
          </f:facet>
          <h:outputText value="#{concurso.codigo}" style="#{!concurso.situacao.habilitado ? 'color: red;' : ''}" />
        </p:column>

        <p:column style="text-align:left;">
          <f:facet name="header">
            <h:outputText value="Identificacao" />
          </f:facet>
          <h:outputText value="#{concurso.identificacao}" style="#{!concurso.situacao.habilitado ? 'color: red;' : ''}" />
        </p:column>

        <p:column style="text-align:left;">
          <f:facet name="header">
            <h:outputText value="Orgão" />
          </f:facet>
          <h:outputText value="#{concurso.orgao.nome}" style="#{!concurso.situacao.habilitado ? 'color: red;' : ''}" />
        </p:column>

        <p:column style="text-align:left;">
          <f:facet name="header">
            <h:outputText value="Instituição" />
          </f:facet>
          <h:outputText value="#{concurso.instituicao.nome}" style="#{!concurso.situacao.habilitado ? 'color: red;' : ''}" />
        </p:column>

        <p:column style="text-align:center;">
          <p:commandLink id="lnkEditData" action="#{adminConcursoAction.prepararAlteracao}" >
            <h:graphicImage value="/images/action_edit.gif" width="16" height="16" style="border: 0px;" title="editar dados concurso" />
            <f:setPropertyActionListener value="#{concurso}" target="#{adminConcursoAction.concurso}" />            
          </p:commandLink>
          <p:spacer width="5" />
          <p:commandLink id="lnkEditDetail" action="#{adminConcursoMateriaAction.listar}" >
            <h:graphicImage value="/images/action_edit_detail.gif" width="16" height="16" style="border: 0px;" title="editar prova concurso" />
            <f:setPropertyActionListener value="#{concurso}" target="#{adminConcursoMateriaAction.concurso}" />            
          </p:commandLink>
          <p:spacer width="5" />
          <p:commandLink id="lnkDesactive" update=":dlgConfirm" oncomplete="varDlgConfirm.show()" rendered="#{concurso.situacao.habilitado}" >
            <h:graphicImage value="/images/action_desabled.gif" width="16" height="16" style="border: 0px;" title="desabilitar concurso" />
            <f:setPropertyActionListener value="#{concurso}" target="#{adminConcursoAction.concurso}" />            
            <f:setPropertyActionListener value="#{true}" target="#{adminConcursoAction.acaoDesativar}" />            
          </p:commandLink>
          <p:commandLink id="lnkActive" update=":dlgConfirm" oncomplete="varDlgConfirm.show()" rendered="#{!concurso.situacao.habilitado}" >
            <h:graphicImage value="/images/action_enabled.gif" width="16" height="16" style="border: 0px;" title="habilitar concurso" />
            <f:setPropertyActionListener value="#{concurso}" target="#{adminConcursoAction.concurso}" />            
            <f:setPropertyActionListener value="#{true}" target="#{adminConcursoAction.acaoAtivar}" />            
          </p:commandLink>
          <p:spacer width="5" />
          <p:commandLink id="lnkDelete" update=":dlgConfirm" oncomplete="varDlgConfirm.show()" >
            <h:graphicImage value="/images/action_delete.gif" width="16" height="16" style="border: 0px;" title="excluir concurso" />
            <f:setPropertyActionListener value="#{concurso}" target="#{adminConcursoAction.concurso}" />            
            <f:setPropertyActionListener value="#{true}" target="#{adminConcursoAction.acaoExcluir}" />            
          </p:commandLink>
        </p:column>

      </p:dataTable>

      <p:spacer height="10" />
      <p:outputPanel id="pnlButons">
        <div align="right" id="divButons">
          <h:commandLink action="#{adminConcursoAction.prepararInclusao}" value="incluir novo concurso" />
        </div>
      </p:outputPanel>			
      <p:spacer height="10" />
      
    </p:panel>
    </h:form>
    
    <p:dialog widgetVar="varDlgConfirm" id="dlgConfirm" header="Confirmação" modal="true" resizable="false" draggable="false" width="250">
      <p:outputPanel id="pnlConfirm">  
      <table width="100%">
        <tbody>
          <tr>
            <td align="center" colspan="2" width="100%">
              <h:outputText value="Confirma #{adminConcursoAction.acao.nome} o concurso?" ></h:outputText>
            </td>
          </tr>
          <tr>
            <td align="center" colspan="2" width="100%">
              <h:outputText style="font-weight:bold" value="#{adminConcursoAction.concurso.codigo} - #{adminConcursoAction.concurso.identificacao}" ></h:outputText>
            </td>
          </tr>
          <tr>
            <td align="center" colspan="2" width="100%" height="10"></td>
          </tr>
          <tr>
            <td align="center" width="50%">
              <p:commandButton value="confirmar" action="#{adminConcursoAction.executarAcao}" update=":frmListaConcursos:tblConcurso" oncomplete="varDlgConfirm.hide();" />
            </td>
            <td align="center" width="50%">
              <p:commandButton value="cancelar" onclick="varDlgConfirm.hide();" />
            </td>
          </tr>
        </tbody>
      </table>
      </p:outputPanel>
    </p:dialog>

  </ui:define>
  </ui:composition>
</html>
